import React, {useEffect, useState} from 'react';
import './index.css'
import {Select} from "antd";
import http from "../../../util/http";

const data = [
    "主管部门",
    "院属企业",
    //"行业组织",
    "友情链接"
]

function Link(props) {

    const [link, setLink] = useState([]);

    useEffect(() => {
        http.doGet( '/model/data/get', {type: "link"}).then(res => {
            if (res.status === 200) {
                setLink(res.data)
            }
        })
    }, [])

    function handleChange(value, option) {
        if (option.url && option.url !== "") {
            option.url.startsWith("http") ? window.open(option.url) : window.open("http://" + option.url, "_blank")
        }
    }

    return (
        <div className="link-main">
            {/*<div className="link-title">友情链接：</div>*/}
            <div className="link-content">
                {
                    data.map((item, index) => {
                        return (
                            <Select
                                placeholder={item}
                                onChange={handleChange}
                                className="link-content-one"
                                key={index}
                                value={item}
                                placement="bottomLeft"
                                bordered={false}
                                options={link[index+""] || []}
                            />
                        )
                    })
                }
            </div>
        </div>
    );
}

export default Link;